package multiples_colas;
// OOSimL v 1.1 File: Customers.java, Mon Mar 19 11:30:50 2012
 
import java.util.*; 
import psimjava.*; 
/** 
description
  The model of the multi-server multi-queue car-wash system
  OOSIMl version,  J Garrido, September 2008

  This class defines behavior of car objects
  After a car object is created it joins the shortest queue to 
  wait for service. If it finds a server object idle,
   it reactivates the server object.
*/
 public  class Customers  extends psimjava.Process     {
static Scanner scan = new Scanner (System.in);
 private int  customerNum; 
  // customer number 
 private double  arrivalTime; 
  // arrival time of customer 
 private double  service_dur; 
  // cust service interval 
 // 
 public Customers( String  cname, double  servdur) { 
super(cname); 
customerNum =  Multiples_colas.num_arrived;
 arrivalTime = StaticSync.get_clock();
service_dur =  servdur;
 // display cname, " arrives at time ", arrivalTime	   
 } // end initializer 
 // 
 public double  get_arrivalT(   ) { 
return arrivalTime; 
 }  // end get_arrivalT 
 // 
 public double  get_serv_dur(   ) { 
return service_dur; 
 }  // end get_serv_dur 
 // 
 public void  Main_body(   ) { 
 double  simclock; 
  String  cname; 
  String  servname; 
  int  mincust; 
  // number of cust in queue 
 int  cqueue; 
  // for selecting shortest queue 
 int  qlength; 
  int  j; 
  Server wmach; 
 simclock = StaticSync.get_clock();
mincust =  1500;
cqueue =   - (1);
cname =  get_name();
System.out.println(cname+ 
" requests service at time "+ 
simclock);
 // check for  the shortest queue 
 for (j = 0 ; j <= (Multiples_colas.num_serv) - (1); j++) { 
qlength = Multiples_colas.car_queue [j].length(); 
System.out.println("length of queue"+ 
j+ 
" is: "+ 
qlength);
 if ( !Multiples_colas.car_queue [j].full()) { 
 // queue not full 
qlength = Multiples_colas.car_queue [j].length(); 
 if ( qlength < mincust) { 
mincust =  qlength;
cqueue =  j;
 // shortest queue so far 
 } // endif 
 } // endif 
 } // endfor 
 // cqueue is index to shortest queue 
 if ( cqueue !=  - (1)) { 
System.out.println(cname+ 
" joins queue "+ 
cqueue+ 
" at "+ 
simclock);
 // join the shortest queue 
Multiples_colas.car_queue [cqueue].into(this );
 // 
System.out.println(cname+ 
" joined queue"+ 
cqueue);
 // now check if server idle  
 if ( Multiples_colas.wash_machine [cqueue].idle()) { 
servname =  Multiples_colas.wash_machine [cqueue].get_name();
System.out.println(cname+ 
" reactivating "+ 
servname+ 
" at "+ 
simclock);
tracedisplay(cname+ 
" reactivating "+ 
Multiples_colas.wash_machine [cqueue].get_name());
 reactivate(Multiples_colas.wash_machine [cqueue]);
 }
 else {
System.out.println("Machine"+ 
cqueue+ 
" is active");
 } // endif 
 // 
System.out.println(cname+ 
" to suspend");
 // to wait for service 
 deactivate(this);
 // 
System.out.println(cname+ 
" reactivated");
 // service completed, do final computation 
 // customers serviced 
 Multiples_colas.num_serviced++;
 // total time in the system: custSojournTime 
 simclock = StaticSync.get_clock();
Multiples_colas.custSojournTime =  (Multiples_colas.custSojournTime) + (( (simclock) - (arrivalTime)) );
System.out.println(cname+ 
" terminates at "+ 
simclock);
  terminate();
 // terminates itself       
 }
 else {
 // queue full, abandon hope                                
 Multiples_colas.num_rejected++;
System.out.println(cname+ 
" rejected, queue full ");
tracedisplay(cname+ 
" rejected, all queues full");
  terminate();
 // terminate this object 
 } // endif 
 }  // end Main_body 
} // end class/interf Customers 
